{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Recommender-System-using-SVD.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "authorship_tag": "ABX9TyPOSQ55wsi8de+tmooQGYsg",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/rposhala/Recommender-System-on-MovieLens-dataset/blob/main/Recommender_System_using_SVD.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "17vYjrcwNXOt"
      },
      "source": [
        "import os\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt"
      ],
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RD2CO0eiNoCX"
      },
      "source": [
        "DATASET_LINK='http://files.grouplens.org/datasets/movielens/ml-100k.zip'"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mD1SZuNdNqV5",
        "outputId": "1c69d5ea-7c54-4ee6-8b43-a5730ede0c9d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 622
        }
      },
      "source": [
        "!wget -nc http://files.grouplens.org/datasets/movielens/ml-100k.zip\n",
        "!unzip -n ml-100k.zip"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "--2020-10-29 14:41:19--  http://files.grouplens.org/datasets/movielens/ml-100k.zip\n",
            "Resolving files.grouplens.org (files.grouplens.org)... 128.101.65.152\n",
            "Connecting to files.grouplens.org (files.grouplens.org)|128.101.65.152|:80... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 4924029 (4.7M) [application/zip]\n",
            "Saving to: ‘ml-100k.zip’\n",
            "\n",
            "ml-100k.zip         100%[===================>]   4.70M  16.2MB/s    in 0.3s    \n",
            "\n",
            "2020-10-29 14:41:19 (16.2 MB/s) - ‘ml-100k.zip’ saved [4924029/4924029]\n",
            "\n",
            "Archive:  ml-100k.zip\n",
            "   creating: ml-100k/\n",
            "  inflating: ml-100k/allbut.pl       \n",
            "  inflating: ml-100k/mku.sh          \n",
            "  inflating: ml-100k/README          \n",
            "  inflating: ml-100k/u.data          \n",
            "  inflating: ml-100k/u.genre         \n",
            "  inflating: ml-100k/u.info          \n",
            "  inflating: ml-100k/u.item          \n",
            "  inflating: ml-100k/u.occupation    \n",
            "  inflating: ml-100k/u.user          \n",
            "  inflating: ml-100k/u1.base         \n",
            "  inflating: ml-100k/u1.test         \n",
            "  inflating: ml-100k/u2.base         \n",
            "  inflating: ml-100k/u2.test         \n",
            "  inflating: ml-100k/u3.base         \n",
            "  inflating: ml-100k/u3.test         \n",
            "  inflating: ml-100k/u4.base         \n",
            "  inflating: ml-100k/u4.test         \n",
            "  inflating: ml-100k/u5.base         \n",
            "  inflating: ml-100k/u5.test         \n",
            "  inflating: ml-100k/ua.base         \n",
            "  inflating: ml-100k/ua.test         \n",
            "  inflating: ml-100k/ub.base         \n",
            "  inflating: ml-100k/ub.test         \n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tkaD_uOCNvjd"
      },
      "source": [
        "#Loading MovieLens dataset"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "atuOW5TGN0fh"
      },
      "source": [
        "Loading u.info -- The number of users, items, and ratings in the u data set."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9_Ok0vy6Nw24",
        "outputId": "d4546608-2088-4767-cb5e-57ae5edb3c2c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "overall_stats = pd.read_csv('ml-100k/u.info', header=None)\n",
        "print(\"Details of users, items and ratings involved in the loaded movielens dataset: \",list(overall_stats[0]))"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Details of users, items and ratings involved in the loaded movielens dataset:  ['943 users', '1682 items', '100000 ratings']\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xP6_W-3IN60_"
      },
      "source": [
        "Loading u.data     -- The full u data set, 100000 ratings by 943 users on 1682 items.\n",
        "\n",
        "---\n",
        "\n",
        "\n",
        "\n",
        "              Each user has rated at least 20 movies.  Users and items are\n",
        "              numbered consecutively from 1.  The data is randomly ordered. This is a tab separated list of \n",
        "\t         user id | item id | rating | timestamp. \n",
        "              The time stamps are unix seconds since 1/1/1970 UTC "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ST78PsBON_2e",
        "outputId": "f0dfb38f-763a-4a33-b08b-3a6566a9c2f7",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        }
      },
      "source": [
        "## same item id is same as movie id, item id column is renamed as movie id\n",
        "column_names1 = ['user id','movie id','rating','timestamp']\n",
        "dataset = pd.read_csv('ml-100k/u.data', sep='\\t',header=None,names=column_names1)\n",
        "dataset.head() "
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>user id</th>\n",
              "      <th>movie id</th>\n",
              "      <th>rating</th>\n",
              "      <th>timestamp</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>196</td>\n",
              "      <td>242</td>\n",
              "      <td>3</td>\n",
              "      <td>881250949</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>186</td>\n",
              "      <td>302</td>\n",
              "      <td>3</td>\n",
              "      <td>891717742</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>22</td>\n",
              "      <td>377</td>\n",
              "      <td>1</td>\n",
              "      <td>878887116</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>244</td>\n",
              "      <td>51</td>\n",
              "      <td>2</td>\n",
              "      <td>880606923</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>166</td>\n",
              "      <td>346</td>\n",
              "      <td>1</td>\n",
              "      <td>886397596</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   user id  movie id  rating  timestamp\n",
              "0      196       242       3  881250949\n",
              "1      186       302       3  891717742\n",
              "2       22       377       1  878887116\n",
              "3      244        51       2  880606923\n",
              "4      166       346       1  886397596"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "67YQURj2OD-4",
        "outputId": "c9fc4320-d84b-4ff9-be67-0aaeca2a3c5a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "len(dataset), max(dataset['movie id']),min(dataset['movie id'])"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(100000, 1682, 1)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3eNaoXfoOG3U"
      },
      "source": [
        "Loading u.item     -- Information about the items (movies); this is a tab separated\n",
        "\n",
        "              list of\n",
        "              movie id | movie title | release date | video release date |\n",
        "              IMDb URL | unknown | Action | Adventure | Animation |\n",
        "              Children's | Comedy | Crime | Documentary | Drama | Fantasy |\n",
        "              Film-Noir | Horror | Musical | Mystery | Romance | Sci-Fi |\n",
        "              Thriller | War | Western |\n",
        "              The last 19 fields are the genres, a 1 indicates the movie\n",
        "              is of that genre, a 0 indicates it is not; movies can be in\n",
        "              several genres at once.\n",
        "              The movie ids are the ones used in the u.data data set.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wefeyoigOHO0",
        "outputId": "16131173-6a4c-40e0-b3b0-2f6c6b218803",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 54
        }
      },
      "source": [
        "d = 'movie id | movie title | release date | video release date | IMDb URL | unknown | Action | Adventure | Animation | Children | Comedy | Crime | Documentary | Drama | Fantasy | Film-Noir | Horror | Musical | Mystery | Romance | Sci-Fi | Thriller | War | Western'\n",
        "column_names2 = d.split(' | ')\n",
        "print(column_names2)"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "['movie id', 'movie title', 'release date', 'video release date', 'IMDb URL', 'unknown', 'Action', 'Adventure', 'Animation', 'Children', 'Comedy', 'Crime', 'Documentary', 'Drama', 'Fantasy', 'Film-Noir', 'Horror', 'Musical', 'Mystery', 'Romance', 'Sci-Fi', 'Thriller', 'War', 'Western']\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kKCtFYT6OMwH",
        "outputId": "7911a631-e033-45d7-dfc3-62f916b28e81",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 758
        }
      },
      "source": [
        "items_dataset = pd.read_csv('ml-100k/u.item', sep='|',header=None,names=column_names2,encoding='latin-1')\n",
        "items_dataset"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>movie id</th>\n",
              "      <th>movie title</th>\n",
              "      <th>release date</th>\n",
              "      <th>video release date</th>\n",
              "      <th>IMDb URL</th>\n",
              "      <th>unknown</th>\n",
              "      <th>Action</th>\n",
              "      <th>Adventure</th>\n",
              "      <th>Animation</th>\n",
              "      <th>Children</th>\n",
              "      <th>Comedy</th>\n",
              "      <th>Crime</th>\n",
              "      <th>Documentary</th>\n",
              "      <th>Drama</th>\n",
              "      <th>Fantasy</th>\n",
              "      <th>Film-Noir</th>\n",
              "      <th>Horror</th>\n",
              "      <th>Musical</th>\n",
              "      <th>Mystery</th>\n",
              "      <th>Romance</th>\n",
              "      <th>Sci-Fi</th>\n",
              "      <th>Thriller</th>\n",
              "      <th>War</th>\n",
              "      <th>Western</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>Toy Story (1995)</td>\n",
              "      <td>01-Jan-1995</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?Toy%20Story%2...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>GoldenEye (1995)</td>\n",
              "      <td>01-Jan-1995</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?GoldenEye%20(...</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>Four Rooms (1995)</td>\n",
              "      <td>01-Jan-1995</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?Four%20Rooms%...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>Get Shorty (1995)</td>\n",
              "      <td>01-Jan-1995</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?Get%20Shorty%...</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>Copycat (1995)</td>\n",
              "      <td>01-Jan-1995</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?Copycat%20(1995)</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1677</th>\n",
              "      <td>1678</td>\n",
              "      <td>Mat' i syn (1997)</td>\n",
              "      <td>06-Feb-1998</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?Mat%27+i+syn+...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1678</th>\n",
              "      <td>1679</td>\n",
              "      <td>B. Monkey (1998)</td>\n",
              "      <td>06-Feb-1998</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?B%2E+Monkey+(...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1679</th>\n",
              "      <td>1680</td>\n",
              "      <td>Sliding Doors (1998)</td>\n",
              "      <td>01-Jan-1998</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/Title?Sliding+Doors+(1998)</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1680</th>\n",
              "      <td>1681</td>\n",
              "      <td>You So Crazy (1994)</td>\n",
              "      <td>01-Jan-1994</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?You%20So%20Cr...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1681</th>\n",
              "      <td>1682</td>\n",
              "      <td>Scream of Stone (Schrei aus Stein) (1991)</td>\n",
              "      <td>08-Mar-1996</td>\n",
              "      <td>NaN</td>\n",
              "      <td>http://us.imdb.com/M/title-exact?Schrei%20aus%...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>1682 rows × 24 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "      movie id                                movie title  ... War  Western\n",
              "0            1                           Toy Story (1995)  ...   0        0\n",
              "1            2                           GoldenEye (1995)  ...   0        0\n",
              "2            3                          Four Rooms (1995)  ...   0        0\n",
              "3            4                          Get Shorty (1995)  ...   0        0\n",
              "4            5                             Copycat (1995)  ...   0        0\n",
              "...        ...                                        ...  ...  ..      ...\n",
              "1677      1678                          Mat' i syn (1997)  ...   0        0\n",
              "1678      1679                           B. Monkey (1998)  ...   0        0\n",
              "1679      1680                       Sliding Doors (1998)  ...   0        0\n",
              "1680      1681                        You So Crazy (1994)  ...   0        0\n",
              "1681      1682  Scream of Stone (Schrei aus Stein) (1991)  ...   0        0\n",
              "\n",
              "[1682 rows x 24 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "va0LfWdWOPlS",
        "outputId": "9ff29312-94fa-4112-b95d-b7439f761818",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        }
      },
      "source": [
        "movie_dataset = items_dataset[['movie id','movie title']]\n",
        "movie_dataset.head()"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>movie id</th>\n",
              "      <th>movie title</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>Toy Story (1995)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>GoldenEye (1995)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>Four Rooms (1995)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>4</td>\n",
              "      <td>Get Shorty (1995)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>5</td>\n",
              "      <td>Copycat (1995)</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   movie id        movie title\n",
              "0         1   Toy Story (1995)\n",
              "1         2   GoldenEye (1995)\n",
              "2         3  Four Rooms (1995)\n",
              "3         4  Get Shorty (1995)\n",
              "4         5     Copycat (1995)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jPAs7eSzOSo3"
      },
      "source": [
        "Looking at length of original items_dataset and length of unique combination of rows in items_dataset after removing movie id column"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xGq7uutfOS4n",
        "outputId": "a7840282-bc5b-4911-baf4-3ef3fdffe2b6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "## looking at length of original items_dataset and length of unique combination of rows in items_dataset after removing movie id column\n",
        "len(items_dataset.groupby(by=column_names2[1:])),len(items_dataset)"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(1664, 1682)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "A2QGg2ccOaIC"
      },
      "source": [
        "We can see there are 18 extra movie id's for already mapped movie title and the same duplicate movie id is assigned to the user in the user-item dataset."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LKHTNFPHOdbD"
      },
      "source": [
        "#Merging required datasets"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2miH5N1TOY7c",
        "outputId": "fb7cb9f5-8fd8-4968-f086-b8ec8c84c2ef",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        }
      },
      "source": [
        "merged_dataset = pd.merge(dataset, movie_dataset, how='inner', on='movie id')\n",
        "merged_dataset.head()"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>user id</th>\n",
              "      <th>movie id</th>\n",
              "      <th>rating</th>\n",
              "      <th>timestamp</th>\n",
              "      <th>movie title</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>196</td>\n",
              "      <td>242</td>\n",
              "      <td>3</td>\n",
              "      <td>881250949</td>\n",
              "      <td>Kolya (1996)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>63</td>\n",
              "      <td>242</td>\n",
              "      <td>3</td>\n",
              "      <td>875747190</td>\n",
              "      <td>Kolya (1996)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>226</td>\n",
              "      <td>242</td>\n",
              "      <td>5</td>\n",
              "      <td>883888671</td>\n",
              "      <td>Kolya (1996)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>154</td>\n",
              "      <td>242</td>\n",
              "      <td>3</td>\n",
              "      <td>879138235</td>\n",
              "      <td>Kolya (1996)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>306</td>\n",
              "      <td>242</td>\n",
              "      <td>5</td>\n",
              "      <td>876503793</td>\n",
              "      <td>Kolya (1996)</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   user id  movie id  rating  timestamp   movie title\n",
              "0      196       242       3  881250949  Kolya (1996)\n",
              "1       63       242       3  875747190  Kolya (1996)\n",
              "2      226       242       5  883888671  Kolya (1996)\n",
              "3      154       242       3  879138235  Kolya (1996)\n",
              "4      306       242       5  876503793  Kolya (1996)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 11
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OqTRx84wOn8k"
      },
      "source": [
        "A dataset is created from the existing merged dataset by grouping the unique user id and movie title combination and the ratings by a user to the same movie in different instances (timestamps) are averaged and stored in the new dataset."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1ZwpiFVyOrM7"
      },
      "source": [
        "Example of a multiple rating scenario by an user to a specific movie:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BUP7kGAOOoyY",
        "outputId": "50dd79ff-34ce-43d6-f571-d3a91e196baa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 106
        }
      },
      "source": [
        "merged_dataset[(merged_dataset['movie title'] == 'Chasing Amy (1997)') & (merged_dataset['user id'] == 894)]"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>user id</th>\n",
              "      <th>movie id</th>\n",
              "      <th>rating</th>\n",
              "      <th>timestamp</th>\n",
              "      <th>movie title</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>4800</th>\n",
              "      <td>894</td>\n",
              "      <td>246</td>\n",
              "      <td>4</td>\n",
              "      <td>882404137</td>\n",
              "      <td>Chasing Amy (1997)</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22340</th>\n",
              "      <td>894</td>\n",
              "      <td>268</td>\n",
              "      <td>3</td>\n",
              "      <td>879896041</td>\n",
              "      <td>Chasing Amy (1997)</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "       user id  movie id  rating  timestamp         movie title\n",
              "4800       894       246       4  882404137  Chasing Amy (1997)\n",
              "22340      894       268       3  879896041  Chasing Amy (1997)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JvhzXCA75Vfz"
      },
      "source": [
        "## Creating a final refined dataset with unique user id, movie name combination and their ratings:\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6t2LGS8oOv_9",
        "outputId": "c95cde04-a43b-4688-9b86-afddcc36230d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        }
      },
      "source": [
        "refined_dataset = merged_dataset.groupby(by=['user id','movie title'], as_index=False).agg({\"rating\":\"mean\"})\n",
        "\n",
        "refined_dataset.head()"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>user id</th>\n",
              "      <th>movie title</th>\n",
              "      <th>rating</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>101 Dalmatians (1996)</td>\n",
              "      <td>2.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1</td>\n",
              "      <td>12 Angry Men (1957)</td>\n",
              "      <td>5.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1</td>\n",
              "      <td>20,000 Leagues Under the Sea (1954)</td>\n",
              "      <td>3.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1</td>\n",
              "      <td>2001: A Space Odyssey (1968)</td>\n",
              "      <td>4.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>1</td>\n",
              "      <td>Abyss, The (1989)</td>\n",
              "      <td>3.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   user id                          movie title  rating\n",
              "0        1                101 Dalmatians (1996)     2.0\n",
              "1        1                  12 Angry Men (1957)     5.0\n",
              "2        1  20,000 Leagues Under the Sea (1954)     3.0\n",
              "3        1         2001: A Space Odyssey (1968)     4.0\n",
              "4        1                    Abyss, The (1989)     3.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_2XqWYvV5h1d"
      },
      "source": [
        "## Creating lists for unique user id's and movie names:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6YV2O4CvOv5u",
        "outputId": "81dd1e52-8bdc-4835-eeb3-2a967b97300d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "#list of all users\n",
        "unique_users = refined_dataset['user id'].unique() \n",
        "#creating a list of all movie names in it\n",
        "unique_movies = refined_dataset['movie title'].unique()\n",
        "len(unique_movies),len(unique_users)"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(1664, 943)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gBHl_tPZ7oCy"
      },
      "source": [
        "## Converting user id, movie name column of refined dataset to respective lists:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CXSqRdqz-4aA",
        "outputId": "c50be8a9-296d-4ee9-e450-60d021fcc2a4",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "users_list = refined_dataset['user id'].tolist()\n",
        "movie_list = refined_dataset['movie title'].tolist()\n",
        "len(users_list),len(movie_list)"
      ],
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(99693, 99693)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 15
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Gxy-Q_aL754R"
      },
      "source": [
        "## Extracting ratings into a list:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KndchZIe0Vp3",
        "outputId": "f44614ca-4ad0-4c36-aca4-3c083cb12270",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 70
        }
      },
      "source": [
        "ratings_list = refined_dataset['rating'].tolist()\n",
        "print(ratings_list)\n",
        "len(ratings_list)"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[2.0, 5.0, 3.0, 4.0, 3.0, 3.0, 1.0, 4.0, 4.0, 5.0, 5.0, 1.0, 5.0, 4.0, 5.0, 3.0, 4.0, 2.0, 4.0, 4.0, 1.0, 5.0, 2.0, 3.0, 1.0, 1.0, 1.0, 3.0, 2.0, 3.0, 5.0, 2.0, 4.0, 5.0, 4.0, 5.0, 3.0, 4.0, 5.0, 1.0, 5.0, 4.0, 4.0, 3.0, 3.0, 3.0, 4.0, 5.0, 5.0, ..., 5.0, 1.0, 3.0, 1.0, 4.0, 4.0, 2.0, 5.0, 5.0, 4.0, 3.0, 5.0, 4.0, 5.0, 5.0, 3.0, 3.0, 4.0, 4.0, 3.0, 4.0, 3.0, 5.0, 4.0, 4.0, 3.0, 4.0, 5.0, 5.0, 4.0, 5.0, 3.0, 3.0, 4.0, 4.0, 4.0, 5.0, 4.0, 4.0, 4.0, 5.0, 5.0, 2.0, 2.0, 5.0, 4.0, 4.0, 4.0, 3.0, 3.0, 5.0, 4.0, 5.0, 5.0, 3.0, 4.0, 4.0, 4.0, 5.0, 4.0, 3.0, 5.0, 5.0, 5.0, 3.0, 4.0, 5.0, 5.0, 3.0, 5.0, 5.0, 5.0, 3.0, 5.0, 5.0, 2.0, 4.0, 5.0, 5.0, 5.0, 5.0, 4.0, 4.0, 5.0, 4.0, 4.0, 5.0, 3.0, 4.0, 5.0, 4.0, 5.0, 4.0, 5.0, 3.0, 3.0, 4.0, 5.0, 4.0, 4.0, 5.0, 5.0, 4.0, 5.0, 5.0, 4.0, 4.0, 5.0, 4.0, 4.0, 4.0, 5.0, 4.0, 5.0, 4.0, 5.0, 3.0, 4.0, 5.0, 4.0, 4.0, 3.0, 5.0, 4.0, 4.0, 4.0, 2.0, 4.0, 1.0, 3.0, 4.0, 1.0, 5.0, 3.0, 3.0, 4.0, 4.0, 2.0, 4.0, 4.0, 2.0, 5.0, 3.0, 2.0, 1.0, 3.0, 4.0, 4.0, 1.0, 5.0, 4.0, 4.0, 4.0, 1.0, 4.0, 5.0, 4.0, 4.0, 4.0, 5.0, 5.0, 4.0, 4.0, 2.0, 4.0, 3.0, 5.0, 4.0, 3.0, 4.0, 2.0, 5.0, 4.0, 2.0, 5.0, 2.0, 2.0, 5.0, 1.0, 5.0, 5.0, 4.0, 2.0, 5.0, 5.0, 5.0, 5.0, 5.0, 4.0, 2.0, 2.0, 4.0, 4.0, 4.0, 2.0, 3.0, 4.0, 4.0, 3.0, 3.0, 4.0, 3.0, 4.0, 4.0, 5.0, 2.0, 4.0, 1.0, 3.0, 1.0, 5.0, 2.0, 2.0, 3.0, 4.0, 2.0, 4.0, 2.0, 2.0, 5.0, 3.0, 3.0, 4.0, 3.0, 2.0, 4.0, 3.0, 5.0, 5.0, 4.0, 5.0, 5.0, 4.0, 2.0, 5.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 1.0, 4.0, 2.0, 4.0, 3.0, 3.0, 4.0, 5.0, 4.0, 5.0, 5.0, 1.0, 3.0, 3.0, 4.0, 2.0, 1.0, 1.0, 1.0, 1.0, 3.0, 4.0, 3.0, 5.0, 3.0, 4.0, 4.0, 4.0, 3.0, 1.0, 5.0, 2.0, 4.0, 4.0, 4.0, 5.0, 4.0, 4.0, 5.0, 4.0, 5.0, 3.0, 5.0, 2.0, 4.0, 2.0, 4.0, 1.0, 3.0, 2.0, 1.0, 4.0, 3.0]\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "99693"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pKPESOnj8BFn"
      },
      "source": [
        "## Creating a dictionary to map movie name to their corresponding index in the unique movie name list"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IqxEfLEXif6R",
        "outputId": "068d9556-810d-4885-c561-1bf242118683",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 70
        }
      },
      "source": [
        "movies_dict = {unique_movies[i] : i for i in range(len(unique_movies))}\n",
        "print(movies_dict)\n",
        "print(len(movies_dict))"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "{'101 Dalmatians (1996)': 0, '12 Angry Men (1957)': 1, '20,000 Leagues Under the Sea (1954)': 2, '2001: A Space Odyssey (1968)': 3, 'Abyss, The (1989)': 4, 'Ace Ventura: Pet Detective (1994)': 5, 'Air Bud (1997)': 6, 'Akira (1988)': 7, 'Aladdin (1992)': 8, 'Alien (1979)': 9, 'Aliens (1986)': 10, 'All Dogs Go to Heaven 2 (1996)': 11, 'Amadeus (1984)': 12, 'Angels and Insects (1995)': 13, \"Antonia's Line (1995)\": 14, 'Apocalypse Now (1979)': 15, ..... , 'Entertaining Angels: The Dorothy Day Story (1996)': 1637, 'Favor, The (1994)': 1638, 'Little City (1998)': 1639, 'Target (1995)': 1640, 'Getting Away With Murder (1996)': 1641, 'Small Faces (1995)': 1642, 'New Age, The (1994)': 1643, 'Rough Magic (1995)': 1644, '8 Heads in a Duffel Bag (1997)': 1645, \"Brother's Kiss, A (1997)\": 1646, 'MURDER and murder (1996)': 1647, 'Next Step, The (1995)': 1648, 'Nothing Personal (1995)': 1649, 'Ripe (1996)': 1650, 'Tainted (1998)': 1651, 'Wedding Bell Blues (1996)': 1652, 'Further Gesture, A (1996)': 1653, 'Kika (1993)': 1654, 'Mirage (1995)': 1655, 'Mamma Roma (1962)': 1656, 'Sunchaser, The (1996)': 1657, 'War at Home, The (1996)': 1658, 'Sweet Nothing (1995)': 1659, 'B. Monkey (1998)': 1660, \"Mat' i syn (1997)\": 1661, 'You So Crazy (1994)': 1662, 'Scream of Stone (Schrei aus Stein) (1991)': 1663}\n",
            "1664\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Dyk5N4CQ8eTG"
      },
      "source": [
        "## Creating a Utility matrix with rows as movies, columns as users, to make the refined dataframe compatible for SVD operations"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xQCQFZoFmk9M",
        "outputId": "043372bf-07c3-489c-c3c8-52f9a5d5fd98",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 151
        }
      },
      "source": [
        "## creating a utility matrix for the available data\n",
        "\n",
        "## Creating an empty array with (number of rows = number of movies) and (number of columns = number of users) rows as movies, columns as users\n",
        "\n",
        "utility_matrix = np.asarray([[np.nan for j in range(len(unique_users))] for i in range(len(unique_movies))])\n",
        "print(\"Shape of Utility matrix: \",utility_matrix.shape)\n",
        "\n",
        "for i in range(len(ratings_list)):\n",
        "\n",
        "  ## ith entry in users list and subtract 1 to get the index, we do the same for movies but we already defined a dictionary to get the index.\n",
        "  utility_matrix[movies_dict[movie_list[i]]][users_list[i]-1] = ratings_list[i]\n",
        "\n",
        "utility_matrix"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Shape of Utility matrix:  (1664, 943)\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[ 2., nan, nan, ..., nan, nan, nan],\n",
              "       [ 5., nan, nan, ..., nan, nan, nan],\n",
              "       [ 3., nan, nan, ..., nan, nan, nan],\n",
              "       ...,\n",
              "       [nan, nan, nan, ..., nan, nan, nan],\n",
              "       [nan, nan, nan, ..., nan, nan, nan],\n",
              "       [nan, nan, nan, ..., nan, nan, nan]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Sbawp-X19TBo"
      },
      "source": [
        "## Normalizing the utility matrix across movies column"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Kehwev_F-blc"
      },
      "source": [
        "mask = np.isnan(utility_matrix)\n",
        "masked_arr = np.ma.masked_array(utility_matrix, mask)\n",
        "temp_mask = masked_arr.T\n",
        "rating_means = np.mean(temp_mask, axis=0)\n",
        "\n",
        "filled_matrix = temp_mask.filled(rating_means)\n",
        "filled_matrix = filled_matrix.T\n",
        "filled_matrix = filled_matrix - rating_means.data[:,np.newaxis]"
      ],
      "execution_count": 19,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WcGCWYTO1kmG",
        "outputId": "2b9ae5eb-4529-4bc3-c870-28676256621a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 235
        }
      },
      "source": [
        "filled_matrix = filled_matrix.T / np.sqrt(len(movies_dict)-1)\n",
        "filled_matrix"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[-0.02227217,  0.01608636, -0.01226094, ...,  0.        ,\n",
              "         0.        ,  0.        ],\n",
              "       [ 0.        ,  0.        ,  0.        , ...,  0.        ,\n",
              "         0.        ,  0.        ],\n",
              "       [ 0.        ,  0.        ,  0.        , ...,  0.        ,\n",
              "         0.        ,  0.        ],\n",
              "       ...,\n",
              "       [ 0.        ,  0.        ,  0.        , ...,  0.        ,\n",
              "         0.        ,  0.        ],\n",
              "       [ 0.        ,  0.        ,  0.        , ...,  0.        ,\n",
              "         0.        ,  0.        ],\n",
              "       [ 0.        ,  0.        ,  0.        , ...,  0.        ,\n",
              "         0.        ,  0.        ]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4N4udwv7A_Bv"
      },
      "source": [
        "Mean values across movies columns are extracted.  \n",
        "Nan's of utility matrix are imputed with mean values extracted.  \n",
        "Later the utility matrix has been normalized across movies to get all ratings to a standard/normal scale."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "d8hm0fzFDP77",
        "outputId": "402a6331-51b4-46ea-aa75-93548f4ad4e4",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "filled_matrix.shape"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(943, 1664)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "c6DtibCbBelJ"
      },
      "source": [
        "## Computing SVD (Singular Value Decomposition) of Utility matrix"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2aTS24TEN9Cv"
      },
      "source": [
        "## Computing the SVD of the input matrix\n",
        "\n",
        "U, S, V = np.linalg.svd(filled_matrix)"
      ],
      "execution_count": 23,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2p2qtdC4Bl7s"
      },
      "source": [
        "## Creating a list of Case insensitive movie names for further use"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lxXk1y4f0wxj"
      },
      "source": [
        "case_insensitive_movies_list = [i.lower() for i in unique_movies]"
      ],
      "execution_count": 39,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gSJ0LSEaBvuu"
      },
      "source": [
        "## Defining a function to calculate the cosine similarity on the given dataframe and extracting requesting number of closely matched movie indices with the help of numpy einsum which valuates the Einstein summation convention on the operands."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3GDCTxTDDQco"
      },
      "source": [
        "#Function to calculate the cosine similarity (sorting by most similar and returning the top N)\n",
        "def top_cosine_similarity(data, movie_id, top_n=10):\n",
        "  index = movie_id \n",
        "  movie_row = data[index, :]\n",
        "  magnitude = np.sqrt(np.einsum('ij, ij -> i', data, data))\n",
        "  similarity = np.dot(movie_row, data.T) / (magnitude[index] * magnitude)\n",
        "  sort_indexes = np.argsort(-similarity)\n",
        "  return sort_indexes[:top_n]"
      ],
      "execution_count": 28,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3VgUlWboC-tU"
      },
      "source": [
        "## Defining a function to get similar movies for the given movie name"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YXej0Ynk1HP2"
      },
      "source": [
        "#k-principal components to represent movies, movie_id to find recommendations, top_n print n results        \n",
        "def get_similar_movies(movie_name,top_n,k = 50):\n",
        "  # k = 50\n",
        "  # movie_id = 1\n",
        "  # top_n = 10\n",
        "  \n",
        "  sliced = V.T[:, :k] # representative data\n",
        "  movie_id = movies_dict[movie_name]\n",
        "  indexes = top_cosine_similarity(sliced, movie_id, top_n)\n",
        "  print(\" \")\n",
        "  print(\"Top\",top_n,\"movies which are very much similar to the Movie-\",movie_name, \"are: \")\n",
        "  print(\" \")\n",
        "  for i in indexes[1:]:\n",
        "    print(unique_movies[i])"
      ],
      "execution_count": 49,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ycb2Ws3jDHuC"
      },
      "source": [
        "In SVD decomposition, Where A is a m x n utility matrix, U is a m x r orthogonal left singular matrix, which represents the relationship between users and latent factors, S is a r x r diagonal matrix, which describes the strength of each latent factor and V is a r x n diagonal right singular matrix, which indicates the similarity between items and latent factors. The latent factors here are the characteristics of the items, for example, the genre of the music. The SVD decreases the dimension of the utility matrix A by extracting its latent factors. It maps each user and each item into a r-dimensional latent space. This mapping facilitates a clear representation of relationships between users and items. "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pMRX3J2wDp_Z"
      },
      "source": [
        "**Dynamically suggesting** movie name from the existing movie corpus we have, based on the user input using try and except architecture."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LvjPjBnIDthD"
      },
      "source": [
        "Defining a function which outputs movie names as suggestion when the user mis spells the movie name. **User might have intended to type any of these movie names.**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ou18jV8PQDmA"
      },
      "source": [
        "# function which takes input and returns suggestions for the user\n",
        "\n",
        "def get_possible_movies(movie):\n",
        "\n",
        "    temp = ''\n",
        "    possible_movies = case_insensitive_movies_list.copy()\n",
        "    for i in movie :\n",
        "      out = []\n",
        "      temp += i\n",
        "      for j in possible_movies:\n",
        "        if temp in j:\n",
        "          out.append(j)\n",
        "      if len(out) == 0:\n",
        "          return possible_movies\n",
        "      out.sort()\n",
        "      possible_movies = out.copy()\n",
        "\n",
        "    return possible_movies"
      ],
      "execution_count": 50,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qvhIwdhpDyip"
      },
      "source": [
        "This function provides user with **movie name suggestions if movie name is mis-spelled** or **Recommends similar movies to the input movie** if the movie name is valid."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aAght7el0XT3"
      },
      "source": [
        "class invalid(Exception):\n",
        "    pass\n",
        "\n",
        "def recommender():\n",
        "    \n",
        "    try:\n",
        "\n",
        "      movie_name = input(\"Enter the Movie name: \")\n",
        "      movie_name_lower = movie_name.lower()\n",
        "      if movie_name_lower not in case_insensitive_movies_list :\n",
        "        raise invalid\n",
        "      else :\n",
        "        # movies_list[case_insensitive_country_names.index(movie_name_lower)]\n",
        "        num_recom = int(input(\"Enter Number of movie recommendations needed: \"))\n",
        "        get_similar_movies(unique_movies[case_insensitive_movies_list.index(movie_name_lower)],num_recom)\n",
        "\n",
        "    except invalid:\n",
        "\n",
        "      possible_movies = get_possible_movies(movie_name_lower)\n",
        "\n",
        "      if len(possible_movies) == len(unique_movies) :\n",
        "        print(\"Movie name entered is does not exist in the list \")\n",
        "      else :\n",
        "        indices = [case_insensitive_movies_list.index(i) for i in possible_movies]\n",
        "        print(\"Entered Movie name is not matching with any movie from the dataset . Please check the below suggestions :\\n\",[unique_movies[i] for i in indices])\n",
        "        print(\"\")\n",
        "        recommender()\n"
      ],
      "execution_count": 46,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VETs7zJu3vFD",
        "outputId": "d7b79b0b-b6c1-4ddd-d772-773405d8f3f1",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 319
        }
      },
      "source": [
        "recommender()"
      ],
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Enter the Movie name: dal\n",
            "Entered Movie name is not matching with any movie from the dataset . Please check the below suggestions :\n",
            " ['101 Dalmatians (1996)', 'Mrs. Dalloway (1997)']\n",
            "Enter the Movie name: 101 Dalmatians (1996)\n",
            "Enter Number of movie recommendations needed: 10\n",
            "Top 10 movies which are very much similar to the Movie- 101 Dalmatians (1996) are: \n",
            " \n",
            "Black Beauty (1994)\n",
            "Free Willy 2: The Adventure Home (1995)\n",
            "Evening Star, The (1996)\n",
            "Robin Hood: Men in Tights (1993)\n",
            "Cool Runnings (1993)\n",
            "Turbo: A Power Rangers Movie (1997)\n",
            "Remains of the Day, The (1993)\n",
            "City Hall (1996)\n",
            "Children of the Corn: The Gathering (1996)\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "stream",
          "text": [
            "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:6: RuntimeWarning: invalid value encountered in true_divide\n",
            "  \n"
          ],
          "name": "stderr"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HE0WgcdUD7RN"
      },
      "source": [
        "## Conclusion:\n",
        "\n",
        "The above built recommender system can suggest movie names similar to the given movie name. The same architecture can be built to get similar users for the given user id and then suggesting movies from those user id's (this would be item-item collaborative filtering). This can be done just by extracting latent factors of U matrix (which corresponds to Users) instead V matrix (which corresponds to Movies) as we did. But a better recommender system can be built only if we could change the axis of normalization of utility matrix to userid from movies."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "G9YUfb5A5Kg3"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "p8sBqW8S5Lz8"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9IZa7DpF5MGL"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6Kr6myjW5Ml_"
      },
      "source": [
        "# Rough Work"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "B5X-Z7D1QDiW",
        "outputId": "cb8a352b-0216-4e7b-b9e4-e7374929349d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "movies_dict['101 Dalmatians (1996)']"
      ],
      "execution_count": 78,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 78
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "17hc3lLlDQDe",
        "outputId": "75d763d2-ad6c-4a5b-b2bd-e4595879576d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "len(movie_list)"
      ],
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "99693"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 48
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VtbcVhCW0ARz",
        "outputId": "bffa5c2c-b1c3-466a-8325-e3c4291ca5f7",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 134
        }
      },
      "source": [
        "util_mat = np.asarray([[np.nan for j in range(4)] for i in range(7)])\n",
        "util_mat[6][3] = 4\n",
        "util_mat[2][3] = 12\n",
        "util_mat[6][0] = 1\n",
        "util_mat[4][1] = 4\n",
        "util_mat[0][2] = 8\n",
        "util_mat[5][1] = 2\n",
        "util_mat[6][3] = 3\n",
        "util_mat[3][1] = 6\n",
        "util_mat[5][0] = 10\n",
        "util_mat[1][3] = 2\n",
        "util_mat[0][2] = 7\n",
        "util_mat[1][0] = 13\n",
        "util_mat"
      ],
      "execution_count": 58,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[nan, nan,  7., nan],\n",
              "       [13., nan, nan,  2.],\n",
              "       [nan, nan, nan, 12.],\n",
              "       [nan,  6., nan, nan],\n",
              "       [nan,  4., nan, nan],\n",
              "       [10.,  2., nan, nan],\n",
              "       [ 1., nan, nan,  3.]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 58
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5comEfTi0IW3",
        "outputId": "69500841-9edf-4351-e63a-49f49c278865",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 134
        }
      },
      "source": [
        "mask = np.isnan(util_mat)\n",
        "masked_arr = np.ma.masked_array(util_mat, mask)\n",
        "transp = masked_arr.T\n",
        "item_means = np.mean(transp, axis=0)\n",
        "# np.mean(utility_matrix,axis=0)\n",
        "s = transp.filled(item_means)\n",
        "s = s.T\n",
        "s"
      ],
      "execution_count": 59,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[ 7. ,  7. ,  7. ,  7. ],\n",
              "       [13. ,  7.5,  7.5,  2. ],\n",
              "       [12. , 12. , 12. , 12. ],\n",
              "       [ 6. ,  6. ,  6. ,  6. ],\n",
              "       [ 4. ,  4. ,  4. ,  4. ],\n",
              "       [10. ,  2. ,  6. ,  6. ],\n",
              "       [ 1. ,  2. ,  2. ,  3. ]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 59
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SkPQTEmH96IF",
        "outputId": "6427e140-39bf-4f68-bd32-bcf83ccfb3d8",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "e = item_means.data\n",
        "e"
      ],
      "execution_count": 50,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 7. ,  7.5, 12. ,  6. ,  4. ,  6. ,  2. ])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 50
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XC-aG00U9Wqf"
      },
      "source": [
        "e = e[:,np.newaxis]"
      ],
      "execution_count": 56,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aaIqSo4K8eTJ",
        "outputId": "46f64732-6668-4462-b1d6-f486c90282a3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 134
        }
      },
      "source": [
        "s.T - e"
      ],
      "execution_count": 57,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[ 0. ,  0. ,  0. ,  0. ],\n",
              "       [ 5.5,  0. ,  0. , -5.5],\n",
              "       [ 0. ,  0. ,  0. ,  0. ],\n",
              "       [ 0. ,  0. ,  0. ,  0. ],\n",
              "       [ 0. ,  0. ,  0. ,  0. ],\n",
              "       [ 4. , -4. ,  0. ,  0. ],\n",
              "       [-1. ,  0. ,  0. ,  1. ]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 57
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZH39mBBy715B",
        "outputId": "25641717-d2ed-4e14-d3c3-31a6082cdd11",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 50
        }
      },
      "source": [
        "d = np.asarray([[2,3,5],[5,6,8]])\n",
        "d - [[2],[5]]"
      ],
      "execution_count": 36,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[0, 1, 3],\n",
              "       [0, 1, 3]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 36
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dQVerReH9POv",
        "outputId": "e7b1bfe4-d30e-4ca3-8dc2-ab8da38ba7ea",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "f = np.asarray([2,5])\n",
        "f.T"
      ],
      "execution_count": 44,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([2, 5])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 44
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Khl0RiRc9lax",
        "outputId": "94c20cb8-758b-4036-e68d-76612c3f4263",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 67
        }
      },
      "source": [
        "k = np.asarray([[2,3,5],[5,6,8],[6,3,1]])\n",
        "k"
      ],
      "execution_count": 37,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[2, 3, 5],\n",
              "       [5, 6, 8],\n",
              "       [6, 3, 1]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 37
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MjWvWZPCDoNH",
        "outputId": "c5812bc0-4345-42d8-f85d-4542d979d25c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "np.einsum('ij, ij -> i', k, k)"
      ],
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 38, 125,  46])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 38
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "j-rpqWG7e30t",
        "outputId": "e9b54a7e-78c5-46b9-f4ae-5b037fe38d17",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "np.einsum('ii, ii', k, k)"
      ],
      "execution_count": 45,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "41"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 45
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Z9saWfdsfBMz",
        "outputId": "6e78d305-1bba-44c8-afc7-3cf724c1383e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "source": [
        "a = [[1,3],[4,6]]\n",
        "np.einsum('ij, ij -> i', a, a)"
      ],
      "execution_count": 46,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([10, 52])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 46
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GWpvRta3fQr3"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}
